﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Niti.OrderManage.Domain.Configurations;
using Niti.OrderManage.OrderManage;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.DependencyInjection;
using Volo.Abp.EntityFrameworkCore.MySQL;
using Volo.Abp.EntityFrameworkCore.Sqlite;
using Volo.Abp.EntityFrameworkCore.SqlServer;
using Volo.Abp.Modularity;

namespace Niti.OrderManage
{
    [DependsOn(typeof(NitiOrderManageDomainModule),
         typeof(AbpEntityFrameworkCoreModule),
         typeof(AbpEntityFrameworkCoreMySQLModule),
         typeof(AbpEntityFrameworkCoreSqlServerModule),
         typeof(AbpEntityFrameworkCoreSqliteModule))]
    public class NitiOrderManageFrameworkCoreModule: AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            context.Services.AddAbpDbContext<NitiOrderManageDbContext>(options =>
            {
                options.AddDefaultRepositories(includeAllEntities: true);
            });

            Configure<AbpDbContextOptions>(options =>
            {
                switch (AppSettings.EnableDb)
                {
                    case "MySQL":
                        options.UseMySQL();
                        break;
                    case "SqlServer":
                        options.UseSqlServer();
                        break;
                    case "Sqlite":
                        options.UseSqlite();
                        break;
                    default:
                        options.UseMySQL();
                        break;
                }
            });

            //Configure<AbpEntityOptions>(options =>
            //{
            //    options.Entity<Order>(DemandOrderOptions =>
            //    {
            //        DemandOrderOptions.DefaultWithDetailsFunc = query => query.Include(o => o.OrderLineItem);
            //    });
            //});

            //Configure<AbpEntityOptions>(options =>
            //{
            //    options.Entity<ReceiptOrder>(DemandOrderOptions =>
            //    {
            //        DemandOrderOptions.DefaultWithDetailsFunc = query => query.Include(o => o.ReceiptOrderLineItem);
            //    });
            //});




        }
    }
}
